home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
096
/
listsort.arc
/
LISTSORT.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1985-08-11
|
4KB
|
137 lines
Program RbbsProgramListingSort (Input,Output,InFile,OutFile);
{ LISTSORT.PAS Version 1.0 }
{ Alphabetizes large, commented, RBBS program directories }
Type
LineType = String[79];
FileNameType = String[12];
FileNameArrayType = Array [1..1730] of FileNameType;
Var
InFile, OutFile: Text;
InFileName, OutFileName: String[15];
Line: LineType;
FileNameArray: FileNameArrayType;
FileName: FileNameType;
Result, I, J, A, B, Index, IndexA, Count, FileLen: Integer;
Ch: Char;
Procedure Opener;
Begin
ClrScr;
WriteLn;
WriteLn ('This program was designed to sort large (500+ listings) RBBS');
WriteLn ('directories into alphabetical order by file name.');
WriteLn;
WriteLn ('Be sure you have approximately as much free disk space');
WriteLn ('as the size of the source file for output.');
WriteLn;
WriteLn;
WriteLn ('Written by: John Tevik');
WriteLn (' 5120 Oakley');
WriteLn (' Duluth, MN 55804');
GotoXY (1,20);
WriteLn ('Press any key to continue');
Repeat Until Keypressed;
Read (Kbd,Ch)
End;
Procedure FillArray (Var FileNameArray: FileNameArrayType; Var Count: Integer);
Var
Index: 1..12;
FileName: FileNameType;
Begin
Reset (InFile);
Count := 0;
While Not (EOF(InFile)) Do
Begin
Count := Count + 1;
ReadLn (InFile,Line);
FileName := '';
For Index := 1 To 12 Do
FileName := FileName + Line[Index];
FileNameArray[Count] := FileName
End;
Close (InFile)
End;
Procedure Swap (Var FileNameArray: FileNameArrayType; A, B: Integer);
Var
Temp: FileNameType;
Begin
Temp := FileNameArray[A];
FileNameArray[A] := FileNameArray[B];
FileNameArray[B] := Temp
End;
Begin
Opener;
ClrScr;
WriteLn ('(Drive ID not necessary if file is on default drive)');
WriteLn;
WriteLn ('Source file drive & name? ');
WriteLn ('Output file drive & name? ');
{ Check that a valid source file was specIfied }
Repeat
GotoXY (27,3);
ClrEOL;
Read (InFileName);
GotoXY (1,7);
ClrEOL;
Assign (InFile,InFileName);
{$I-} Reset (InFile); {$I+}
Result := IOResult;
If Result <> 0 Then
Begin
GotoXY (1,7);
Write ('File not found! ');
Write ('Please check disk or enter another file name.')
End;
Until Result = 0;
GotoXY (27,4);
ReadLn (OutFileName);
Assign (OutFile,OutFileName);
FillArray (FileNameArray,FileLen);
WriteLn; WriteLn;
Write ('SortIng filenames in memory... ');
For I := FileLen-1 DownTo 1 Do
For J := 1 To I Do
If FileNameArray[J] > FileNameArray[J+1] Then
swap (FileNameArray,J,J+1);
WriteLn ('Done');
WriteLn;
{ FInd the match for FileNameArray[Index] in the source }
{ file and write it into place in the target file }
Write ('WritIng sorted data to ASCII file: ');
For Index := 1 To 15 Do
OutFileName[Index] := UpCase(OutFileName[Index]);
Write (OutFileName,'... ');
Reset (InFile);
ReWrite (OutFile);
For Index := 1 To FileLen Do
If Not EOF(InFile) Then
Begin
Repeat
FileName := '';
ReadLn (InFile,Line);
For IndexA := 1 To 12 Do
FileName := FileName + Line[IndexA];
Until (FileNameArray[Index] = FileName) or (EOF(InFile));
{ Remove excess spaces }
Count := 79;
While (Line[Count] = ' ') or
((Line[Count] = '0') and (Line[Count-1] = ' ')) Do
Count := Count - 1;
Delete (Line,Count+1,79-Count);
WriteLn (OutFile,Line);
Reset (InFile)
End;
Close (OutFile);
Close (InFile);
WriteLn ('Done');
GotoXY (1,18);
WriteLn ('ListSort fInished.');
GotoXY (1,23)
End.